import axios from '../axiosconfig'
import {AxiosPromise} from 'axios'

export interface Topic {
    id: number,
    key: string,
    name: string,
    topicCode: string,
    createTime: string,
    subCount: string,
    doc: string
}

export interface SubTopic {
    id: number,
    name: string,
    parentId: number,
    practiceCount: number,
    params: any,
    createTime: Date

}

export function getTopics(): AxiosPromise<Array<Topic>> {
    return axios.get('topic/allMap', {})
}

export function getSubTopics(topicId: number): AxiosPromise<Array<SubTopic>> {
    return axios.get('topic/subTopicList', {params: {topicId: topicId}})
}

export const getWordData = function (key: string, params: any) {
    return axios.get(key, {params: params})
}

export function startTopic(usbTopicId: number): AxiosPromise<number> {
    return axios.get('static/startSubTopic', {params: {usbTopicId: usbTopicId}})
}

export function endTopic(usbTopicId: number): AxiosPromise<any> {
    return axios.get('static/endSubTopic', {params: {usbTopicId: usbTopicId}})
}

export const byLen = function (len: number) {
    return axios.get('getWordByLen', {params: {len: len}});
}
